package com.ibm.android.validator;

public class EmailValidator implements Validator{
	
	private static final char[] ATEXT_SYMBOLS =
    {'@','.','!','#','$','%','&','\'','*','+','-','/','=','?','^','_','`','{','|','}','~'};
	
	public boolean isAValidInput(String email) {
	    if (email == null) {
	      return false;
	    }
	    boolean atFound = false;
	    for (int i = 0; i < email.length(); i++) {
	      char c = email.charAt(i);
	      if ((c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && (c < '0' || c > '9') &&
	          !isAtextSymbol(c)) {
	        return false;
	      }
	      if (c == '@') {
	        if (atFound) {
	          return false;
	        }
	        atFound = true;
	      }
	    }
	    return atFound;
	}
	
	public static boolean isAtextSymbol(char c) {
	    for (int i = 0; i < ATEXT_SYMBOLS.length; i++) {
	      if (c == ATEXT_SYMBOLS[i]) {
	        return true;
	      }
	    }
	    return false;
	  }

}
